package com.commutersconnect;

import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.LinearLayout;
import com.google.android.maps.*;

/**
 * This is the launching page of the Commuters Connect Android application.
 * Provides a map view of where the user currently is, if available, along
 * with overlays showing any reports in the given area.  Does offer a context
 * menu to create a new report.
 *
 * Much of this class simply comes straight from the Map tutorial.
 */
public class Main extends MapActivity {

    private LinearLayout linearLayout;
    private MapView mapView;
    List<Overlay> mapOverlays;
    Drawable drawable;
    ReportsOverlay reportsOverlay;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.getController().setCenter(new GeoPoint(33754600, -84387000));
        mapView.getController().setZoom(12);


        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.pin);
        reportsOverlay = new ReportsOverlay(drawable);
        GeoPoint point = new GeoPoint(33754600, -84387000);
        OverlayItem overlayitem = new OverlayItem(point, "a", "a");
        reportsOverlay.addReport(overlayitem);
        mapOverlays.add(reportsOverlay);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.new_report:
            Intent intent = new Intent(this, NewReport.class);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
}
